Fix: Pass timeout to SOCKS5 handshake to prevent hanging#1055
Open
drshvik wants to merge 3 commits intoencode:masterfrom
Open
Fix: Pass timeout to SOCKS5 handshake to prevent hanging#1055drshvik wants to merge 3 commits intoencode:masterfrom
drshvik wants to merge 3 commits intoencode:masterfrom
Conversation
Author
|
All checks are passing and I'm happy to make any changes if needed. Thanks! |
Author
|
I noticed this appears to address the same issue as #1017. I've submitted this fresh PR because I verified the bug still exists on the current main branch, and I ensured this version passes all current linting and test checks. Happy to supersede the older PR if that one is inactive. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical issue where
SOCKSProxyignores the configuredconnecttimeout during the SOCKS5 handshake.Previously, the timeout was used to establish the initial TCP connection, but it was not passed to the
_init_socks5_connectionfunction. As a result, if a proxy server accepted the TCP connection but failed to send data (e.g., a "blackhole" server), the client would hang indefinitely (or until the OS socket timeout) regardless of the user's configuredtimeout.The Fix
_init_socks5_connectionin both_sync/socks_proxy.pyand_async/socks_proxy.pyto accept atimeoutargument.timeoutexplicitly to allstream.read()andstream.write()calls during the authentication and connection negotiation phases.Socks5Connection.handle_request(and its async counterpart) to extract the connect timeout fromrequest.extensionsand pass it to the initialization function.Reproduction
I verified this fix using a local reproduction script that simulates a hanging SOCKS5 proxy.
TimeoutExceptionafter 2s.Checklist